// pages/seek/detail/index.js
const app = getApp();
var serverUrl = app.globalData.serverUrl;
var mapKey = app.globalData.mapKey;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    autoplay: true,
    circular: true,
    vertical: false,
    duration: 500,
    interval: 3000,
    sexArr:["男", "女"],
    markers:[{
      iconPath: '/asset/img/location.png',
      id: 0,
      latitude: 31.11325,
      longitude: 121.38206,
      width: 50,
      height: 50
    }],
    circles:[{
      latitude: 31.11325,
      longitude: 121.38206,
      color: "#ff0000",
      fillColor: "#ff000010",
      radius: 50,
      scale:10
    }],
    subkey: mapKey,
    mapShow: false,
    data: {},
    scale: 16,
    disabled:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    var that = this;
    wx.request({
      url: serverUrl+'api/v1/seeks/detail/id/'+id,
      method: "GET",
      dataType: "json",
      success:function(data){
        data = data.data;
        console.log(data);
        if(data.code == 200){
          let markers = that.data.markers;
          markers[0].latitude = data.data.clud.lat;
          markers[0].longitude = data.data.clud.lon;
          let circles = that.data.circles;
          circles[0].latitude = data.data.clud.lat;
          circles[0].longitude = data.data.clud.lon;
          circles[0].radius = data.data.radius;
          that.setData({
            data: data.data,
            markers: markers,
            circles: circles,
            scale: data.data.level,
            disabled: data.data.disabled
          })
          wx.setNavigationBarTitle({
            title: data.data.title
          })
        } else {
          wx.showToast({
            title: '服务器出错!正在返回首页',
            icon: 'none',
            duration: 2000
          })
          setTimeout(function () {
            wx.switchTab({
              url: '../../index/index',
            })
          }, 2000)
        }
      },
      error:function(data){
        wx.showToast({
          title: '服务器出错!正在返回首页',
          icon: 'none',
          duration: 2000
        })
        setTimeout(function(){
          wx.switchTab({
            url: '../../index/index',
          })
        }, 2000)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 显示地图
   */
  showMap:function(){
    var that = this;
    if (!that.data.disabled){
      that.setData({
        mapShow: !that.data.mapShow
      })
    }
  }
})